---@diagnostic disable: undefined-global

local jitu = fk.CreateSkill{
  name = "lvshi__jitu",
  frequency = "active",
}

local ls = require "packages/lvshi/utility"

jitu:addEffect("active", {
  anim_type = "offensive",
  prompt = "#jitu-active",
  max_phase_use_time = 1,
  target_num = 1,
  target_filter = function(self, player, to_select)
    return to_select ~= player and to_select:getHandcardNum() == player:getHandcardNum() and not to_select:isKongcheng()
    and player.role_shown and to_select.role_shown and not ls:isFriend(player, to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    
    if not target or target.dead or player.dead then return end
    local handcard_num = target:getHandcardNum()
    local record_hp = player.hp
    for i = 1, handcard_num do
      if player.dead or target.dead then break end
      local use = room:useVirtualCard("lvshi__fire_attack", nil, target, player, jitu.name)
      
      -- 检查火攻是否造成伤害
      if not use.damageDealt and not player.dead then
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = jitu.name,
        })
      end
    end
    if not player:isWounded() or player.hp < record_hp then
      room:askToUseVirtualCard(player, { name = "lvshi__collaborate", skill_name = jitu.name })
    end
  end,
})

Fk:loadTranslationTable{
  ["lvshi__jitu"] = "棘途",
  [":lvshi__jitu"] = "阶段技，你可令一名手牌数与你相同的对方角色视为对你使用等量张【火攻】，之未造成伤害后你回复1点体力，然后若你的体力值减少或等于体力上限，你可视为使用一张【里应外合】。",
  
  ["#jitu-active"] = "棘途：选择一名手牌数与你相同的角色，其视为对你使用等量张火攻",
  
  ["$lvshi__jitu1"] = "穷途末路,恰是英才豹变时。",
  ["$lvshi__jitu2"] = "山穷水尽，唯效豹变可求生。",
}



return jitu